package com.ficus.road.maintain.controller.third;

import com.ficus.road.maintain.core.model.IdResult;
import com.ficus.road.maintain.core.model.third.DiankeCreateHitRequest;
import com.ficus.road.maintain.core.model.third.DiankeDichargeHitRequest;
import com.ficus.road.maintain.service.third.DiankeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Slf4j
@RequiredArgsConstructor
public class DiankeController {

    private final DiankeService diankeService;
    @RequestMapping(value = "/dianke/hits",
            produces = {"application/json"},
            consumes = {"application/json"},
            method = RequestMethod.POST)
    public ResponseEntity<IdResult> createHit(@RequestBody @Valid DiankeCreateHitRequest request) {
        return new ResponseEntity<>(IdResult.builder().id(diankeService.createHit(request)).build(), HttpStatus.OK);
    }

    @RequestMapping(value = "/dianke/hits/{hitId}/discharge",
            produces = {"application/json"},
            consumes = {"application/json"},
            method = RequestMethod.POST)
    public ResponseEntity<IdResult> discharge(@Valid @RequestBody DiankeDichargeHitRequest request, @PathVariable String hitId) {
        return new ResponseEntity<>(IdResult.builder().id(diankeService.discharge(request, hitId)).build(), HttpStatus.OK);
    }
}
